import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
  createWebHashHistory,
  Router
} from "vue-router";
import Layout from "@/layout/index.vue";
import ParentView from '@/components/ParentView/index.vue'
// 扩展继承属性
interface extendRoute {
  hidden?: boolean;
}

//
import tableRouter from "./modules/table";
import dataScreenRouter from "./modules/dataScreen";
import excelRouter from "./modules/excel";
import nestedRouter from "./modules/nested";
import systemRouter from "./modules/system";
import echartsRouter from "./modules/echarts";
import chatRouter from "./modules/chat";
import othersRouter from "./modules/other";
import externalLink from "./modules/externalLink";
import formRouter from "./modules/form";
import functionPageRouter from "./modules/functionPage";
import { asnycRouters } from "@/routers/modules/asnyc";
import component from "*.vue";

// 异步组件
export const asyncRoutes = [
  // ...dataScreenRouter,
  // ...echartsRouter,
  // ...tableRouter,
  // ...formRouter,
  // ...othersRouter,
  // ...functionPageRouter,
  // ...chatRouter,
  // ...nestedRouter,
  // ...excelRouter,
  // ...externalLink,
 /* ...systemRouter,*/
  ...asnycRouters
];

/**
 * path ==> 路由路径
 * name ==> 路由名称
 * component ==> 路由组件
 * redirect ==> 路由重定向
 * alwaysShow ==> 如果设置为true，将始终显示根菜单，无论其子路由长度如何
 * hidden ==> 如果“hidden:true”不会显示在侧边栏中（默认值为false）
 * keepAlive ==> 设为true 缓存
 * meta ==> 路由元信息
 * meta.title ==> 路由标题
 * meta.icon ==> 菜单icon
 * meta.affix ==> 如果设置为true将会出现在 标签栏中
 * meta.breadcrumb ==> 如果设置为false，该项将隐藏在breadcrumb中（默认值为true）
 */

export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/errorPages/404.vue"),
    hidden: true
  },
  {
    path: "/403",
    name: "403",
    component: () => import("@/views/errorPages/403.vue"),
    hidden: true
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
    hidden: true,
    meta: { title: "登录" }
  },
  {
    path: "/register",
    name: "Register",
    component: () => import("@/views/register/index.vue"),
    hidden: true,
    meta: { title: "注册" }
  },
  {
    path: "/",
    name: "layout",
    component: Layout,
    redirect: "/home",
    meta: { title: "首页", icon: "home" },
    children: [
      {
        path: "/home",
        component: () => import("@/views/home/index.vue"),
        name: "home",
        meta: { title: "首页", icon: "home", affix: true, role: ["other"] }
      }
    ]
  },
  {
    path: "/userCenter",
    name: "userCenter",
    component: Layout,
    redirect: "/userCenter/index",
    meta: { title: "个人中心" },
    hidden: true,
    children: [
      {
        path: "/userCenter/index",
        component: () => import("@/views/userCenter/index.vue"),
        name: "userCenter",
        meta: { title: "个人中心" }
      }
    ]
  },
];

/**
 * notFoundRouter(找不到路由)
 */
export const notFoundRouter = {
  path: "/:pathMatch(.*)",
  name: "notFound",
  redirect: "/404"
};

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL), // history
  history: createWebHashHistory(), // hash
  routes: constantRoutes
});

export default router;
